/**
 * 
 */
package com.trungkent.smsbackup.components;

import com.trungkent.smsbackup.R;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.Checkable;
import android.widget.RelativeLayout;

/**
 * This class is useful for using inside of ListView that needs to have
 * checkable items.
 */
public class CheckableLinearLayout extends RelativeLayout implements Checkable {
	private ImageViewCheckable _checkbox;

	public CheckableLinearLayout(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	@Override
	protected void onFinishInflate() {
		super.onFinishInflate();
		// find checked text view
		int childCount = getChildCount();
		for (int i = 0; i < childCount; ++i) {
			View v = getChildAt(i);
			_checkbox = (ImageViewCheckable) v.findViewById(R.id.imgChecker);
			
		}
	}

	@Override
	public boolean isChecked() {
		return _checkbox != null ? _checkbox.isChecked() : false;
	}

	@Override
	public void setChecked(boolean checked) {
		Log.d("trung", "here");
		if (_checkbox != null) {
			_checkbox.setChecked(checked);
		}
	}

	@Override
	public void toggle() {
		if (_checkbox != null) {
			_checkbox.toggle();
		}
	}
}
